# source $HOME/alchemy-ubuntu-v0.5a/alchemy-setup && alc-on
ALCHEMY_HOME:=$(HOME)/alchemy-ubuntu-v0.5a
ASC:=$(ALCHEMY_HOME)/bin/asc.jar 
PATH:=$(ALCHEMY_HOME)/achacks:$(ALCHEMY_HOME)/bin:$(PATH)
#SWFBRIDGE:=$(ALCHEMY_HOME)/bin/swfbridge
FLEX_HOME:=$(HOME)/flex_sdk_4.5
FLASHPLAYER:=$(FLEX_HOME)/bin/flashplayerdebugger
MXMLC:=$(FLEX_HOME)/bin/mxmlc
ADL:=$(FLEX_HOME)/bin/adl
SWF:=test.swf
AS3_PATH:=.
AS3:=$(AS3_PATH)/test.as
SWC:=jpeg.swc
SRC:= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcprepct.c jcsample.c jdatadst.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jmemansi.c jmemmgr.c jutils.c rdbmp.c rdtarga.c jpeg.c # bytearray.c
OBJS:= $(patsubst %.c,%.o,$(SRC))
CFLAGS:=-D as_api -O3 -Wall
CC:=$(ALCHEMY_HOME)/achacks/gcc

all: $(SWF)
#	echo $(shell ls /)
#	$(FLASHPLAYER) $(SWF)
	$(ADL) test.xml
	cp $(SWC) $(HOME)/jiapu2/src/jpeg.swc

$(SWF): $(SWC) $(AS3) $(SRC)
	$(MXMLC) -strict=true  -tools-locale en_US -omit-trace-statements=false -verbose-stacktraces=true -debug=true -source-path=$(AS3_PATH) -library-path+=$(SWC) $(AS3) -o $(SWF)

$(SWC): $(OBJS)
	ALCHEMY_HOME=$(ALCHEMY_HOME) ASC=$(ASC) $(CC) $(OBJS) $(CFLAGS) -swc -o $(SWC)

.c.o:
	ALCHEMY_HOME=$(ALCHEMY_HOME) $(CC) $(CFLAGS) -c $<

clean:
	rm -rf *.swc *.o *.swf *.achacks.* a.out *.dSYM
